//
//  RigisterCell.swift
//  DollBuy
//
//  Created by 郑东喜 on 2016/11/18.
//  Copyright © 2016年 郑东喜. All rights reserved.
//

import UIKit

class RigisterCell: UITableViewCell {
    
    
    //tf的文字
    var nameLabel: UITextField = {
        let lab = UITextField()
        lab.frame = CGRect(x: 50, y: 0, width: UIScreen.main.bounds.size.width - 60 , height: 45)
        lab.placeholder = "ddd"
        //文字左对齐
        lab.textAlignment = NSTextAlignment.left
        lab.font = UIFont.systemFont(ofSize: 14)
        return lab
    }()
    
    //前置图片
    lazy var imgView: UIImageView = {
        let img = UIImageView()
        //自适应放大
        img.contentMode = UIViewContentMode.scaleAspectFit
        img.frame = CGRect(x: 7.5, y: 7.5, width: 30, height: 30)
        return img
    }()
    
    //分割线
    lazy var line : UIView = {
        let lin = UIView()
        lin.frame = CGRect(x: 0, y: 45, width: UIScreen.main.bounds.size.width, height: 0.5)
        lin.backgroundColor = UIColor.lightGray
        return lin
    }()
    
    //确定按钮
    lazy var btn : UIButton = {
        let btn = UIButton()
        btn.backgroundColor = UIColor.orange
        btn.setTitle("确定", for: .normal)
        btn.frame = CGRect(x: 15, y: 0, width: Int(UIScreen.main.bounds.size.width - 30), height: 40)
        btn.addTarget(self, action: #selector(RigisterCell.confirmSEL), for: .touchUpInside)
        btn.layer.cornerRadius = 8
        return btn
    }()
    
    //验证码按钮
    lazy var yzmBtn : UIButton = {
        let btn = UIButton()
        btn.backgroundColor = UIColor.orange
         btn.frame = CGRect(x: SW - 15 - 100, y: 7.5, width: 100, height: 30)
        btn.backgroundColor = UIColor.orange
        btn.layer.cornerRadius = 8
        btn.setTitle("获取验证码", for: .normal)
        btn.addTarget(self, action: #selector(RigisterCell.autoSEL), for: .touchUpInside)
        btn.titleLabel?.font = UIFont.systemFont(ofSize: 13)

        return btn
    }()
    
    //复选框
    lazy var seleBtn : UIButton = {
        let btn = UIButton()
        btn.frame = CGRect(x: 15, y: 7.5, width: 15, height: 15)
        btn.backgroundColor = UIColor.clear
        btn.layer.borderWidth = 1
        btn.layer.cornerRadius = 2
        btn.addTarget(self, action: #selector(RigisterCell.autoAgreeSEL), for: .touchUpInside)

        return btn
    }()
    
    //复选框图片
    lazy var seleBtnImg : UIImageView = {
        let btn = UIImageView()
        btn.frame = CGRect(x: 15, y: 7.5, width: 15, height: 15)
        btn.backgroundColor = UIColor.orange
        return btn
    }()
    
    //注意事项文字前半段不加单机事件
    lazy var frontNotiLabel : UILabel = {
        let lab = UILabel()
        lab.frame = CGRect(x: 18 + 15, y: 7, width: 72, height: 15)
        lab.text = "我已阅读并同意"
//        lab.layer.borderWidth = 1
//        lab.sizeToFit()
        lab.font = UIFont.systemFont(ofSize: 10)
        return lab
    }()
    
    //注意事项文字后半段加单机事件
    lazy var backNotiLabel : UndelLineLabel = {
        let lab = UndelLineLabel()
        lab.text = "用户使用协议"
        lab.textColor = UIColor.orange
        lab.font = UIFont.systemFont(ofSize: 10)
        lab.isUserInteractionEnabled = true
        //单机手势，使其可以跳转页面
        let tapGes = UITapGestureRecognizer.init(target: self, action: #selector(RigisterCell.clickLabelSEL))
        lab.addGestureRecognizer(tapGes)
        
        return lab
    }()
    
    //重写构造方法
    override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        
          backNotiLabel.frame = CGRect(x: frontNotiLabel.frame.size.width + 18 + 15, y: 7, width: 72, height: 15)
        
        //添加控件
        addSubview(nameLabel)
        addSubview(imgView)
        addSubview(line)
        addSubview(btn)
        addSubview(yzmBtn)
        
        addSubview(seleBtnImg)
        addSubview(seleBtn)
        addSubview(frontNotiLabel)
        addSubview(backNotiLabel)
        
        

        //去除高亮效果
        self.selectionStyle = .none
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

    

    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }

}

extension RigisterCell {
    //确定事件
    func confirmSEL() -> Void {
        print("单机确定")
    }
    
    //验证码事件
    func autoSEL() -> Void {
        print("单机验证码阿牛")
    }
    
    //验证码同意事件
    func autoAgreeSEL() -> Void {
        print("同意注册事项")
    }
    
    //注册协议
    func clickLabelSEL() -> Void {
        print("同意条件")
    }
}
